<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>2_受控组件</title>
</head>
<body>
    <script src="../React-js/react.development.js" type="text/javascript"></script>
    <script src="../React-js/react-dom.development.js" type="text/javascript"></script>
    <script src="../React-js/babel.min.js" type="text/javascript"></script>
    <div id="test"></div>
    <script type="text/babel">
       class Login extends React.Component{
        state = {
            username:'',
            password:''
        }
        handleSubmit = (event)=>{
            event.preventDefault()
            console.log(this.state.username,this.state.password);
        }
        saveUsername = (event)=>{
            this.setState({username:event.target.value})
        }
        savePassword = (event)=>{
            const { password } = this.state
            this.setState({password:event.target.value})
        }
        render(){
            return (
                <form action="http://www.baidu.com" onSubmit={this.handleSubmit}>
                    用户名：<input type="text" onChange={this.saveUsername} name="username"/>
                    密码：<input type="password"  onChange={this.savePassword} name="password"/>
                    <button>登录</button>
                </form>
            )
        }
       }
       ReactDOM.render(<Login/>,document.querySelector('#test'))
    </script>
</body>
</html>